#include <iostream>
#include <queue>
#include <vector>
using namespace std;

const int kMaxAi = 5e4 + 10;
const int kInf = 1e9;

bool used[kMaxAi];
vector<int> edges;
int dist[kMaxAi];

void Dijkstra(int n) {
  priority_queue<pair<int, int>> pq;
  fill(dist, dist + n, kInf);
  dist[0] = 0;
  pq.emplace(-dist[0], 0);
  while (!pq.empty()) {
    int d = -pq.top().first, u = pq.top().second;

    pq.pop();
    if (dist[u] != d) {
      continue;
    }
    for (int e : edges) {
      int v = (u + e) % n;

      if (dist[v] > d + (u + e) / n) {
        dist[v] = d + (u + e) / n;
        pq.emplace(-dist[v], v);
      }
    }
  }
}

int main() {
  ios::sync_with_stdio(0);

  int n, a1;

  cin >> n;
  cin >> a1;

  used[0] = true;
  for (int i = 1; i < n; i++) {
    int a;

    cin >> a;
    if (used[a % a1]) {
      continue;
    }
    used[a % a1] = true;
    edges.emplace_back(a);
  }

  Dijkstra(a1);
  int q;
  for (cin >> q; q; q--) {
    int a_;

    cin >> a_;
    if (dist[a_ % a1] <= a_ / a1) {
      cout << "TAK\n";
    } else {
      cout << "NIE\n";
    }
  }
  return 0;
}